package com.zj.fx.service.month;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zj.fx.common.base.BaseService;
import com.zj.fx.common.support.ConvertUtil;
import com.zj.fx.mapper.month.MonthAuditDtlMapper;
import com.zj.fx.model.custom.Tablepar;
import com.zj.fx.model.month.MonthAuditDtl;
import com.zj.fx.model.month.MonthAuditDtlExample;
import com.zj.fx.shiro.util.ShiroUtils;
import com.zj.fx.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 月度审核部门完成情况明细 MonthAuditDtlService
 *
 * @author SQL_自动生成
 * @Title: MonthAuditDtlService.java 
 * @Package com.zj.fx.service 
 * @email ${email}
 * @date 2023-06-26 11:07:35  
 **/
@Service
public class MonthAuditDtlService implements BaseService<MonthAuditDtl, MonthAuditDtlExample> {
    @Autowired
    private MonthAuditDtlMapper monthAuditDtlMapper;


    /**
     * 分页查询
     *
     * @param
     * @param
     * @return
     */
    public PageInfo<MonthAuditDtl> list(Tablepar tablepar, MonthAuditDtl monthAuditDtl) {
        MonthAuditDtlExample testExample = new MonthAuditDtlExample();
        //搜索
        if (StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
            testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
        } else {//大搜索
            testExample.createCriteria().andLikeQuery(monthAuditDtl);
        }
        //表格排序
        //if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
        //	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
        //}else{
        //	testExample.setOrderByClause("id ASC");
        //}
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<MonthAuditDtl> list = monthAuditDtlMapper.selectByExample(testExample);
        PageInfo<MonthAuditDtl> pageInfo = new PageInfo<MonthAuditDtl>(list);
        return pageInfo;
    }

    @Override
    public int deleteByPrimaryKey(String ids) {

        List<String> lista = ConvertUtil.toListStrArray(ids);
        MonthAuditDtlExample example = new MonthAuditDtlExample();
        example.createCriteria().andIdIn(lista);
        return monthAuditDtlMapper.deleteByExample(example);


    }


    @Override
    public MonthAuditDtl selectByPrimaryKey(String id) {

        return monthAuditDtlMapper.selectByPrimaryKey(id);

    }


    @Override
    public int updateByPrimaryKeySelective(MonthAuditDtl record) {
        return monthAuditDtlMapper.updateByPrimaryKeySelective(record);
    }


    /**
     * 添加
     */
    @Override
    public int insertSelective(MonthAuditDtl record) {

        //添加雪花主键id
        record.setId(SnowflakeIdWorker.getUUID());


        return monthAuditDtlMapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(MonthAuditDtl record, MonthAuditDtlExample example) {

        return monthAuditDtlMapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(MonthAuditDtl record, MonthAuditDtlExample example) {

        return monthAuditDtlMapper.updateByExample(record, example);
    }

    @Override
    public List<MonthAuditDtl> selectByExample(MonthAuditDtlExample example) {

        return monthAuditDtlMapper.selectByExample(example);
    }


    @Override
    public long countByExample(MonthAuditDtlExample example) {

        return monthAuditDtlMapper.countByExample(example);
    }


    @Override
    public int deleteByExample(MonthAuditDtlExample example) {

        return monthAuditDtlMapper.deleteByExample(example);
    }

    /**
     * 根据部门id和Taskid查询
     * @param monthAuditDtl
     * @return
     */
    public List<MonthAuditDtl> findbyTaskIDandDepID(MonthAuditDtl monthAuditDtl) {
        MonthAuditDtlExample monthAuditDtlExample = new MonthAuditDtlExample();
        MonthAuditDtlExample.Criteria criteria = monthAuditDtlExample.createCriteria();
        criteria.andFkTaskIdEqualTo(monthAuditDtl.getFkTaskId());
        criteria.andDeptIdEqualTo(ShiroUtils.getDepId());
        return monthAuditDtlMapper.selectByExample(monthAuditDtlExample);
    }

    public List<MonthAuditDtl> selectByFkTaskId(MonthAuditDtl monthAuditDtl) {
        return monthAuditDtlMapper.selectByFkTaskId(monthAuditDtl);
    }
}
